<%@ page language="java"  pageEncoding="utf-8"%>
<%@taglib uri="/WEB-INF/struts-tags.tld" prefix="s"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>发布信息</title>
<%@include file="../common/jscss.jsp" %>
</head>

<body>
	<!-- head -->
	<%@include file="../common/header.jsp" %>
    <!-- head--end -->
    
    <!-- body -->
    <div class="content">
    	<div class="body_wrap clearfix">
            <div class="com_left">
            	<div class="com_pd_s1">
                	<div class="box_s2">
                    	<div class="title"><img src="images/other/icon_16.jpg"><span>信息发布</span></div>
                        <div class="content">
                        	<div class="p_upfile">
                        		<table class="form_info">
                            	<tbody><tr>
                                	<td width="87" class="col1">标题：</td>
                                    <td><input type="text" class="def_txt_s1" name="title" id="title" value="<s:property value="news.title"/>"/></td>
                                </tr>
                                <tr>
                                	<td width="87" class="col1">板块：</td>
                                    <td>
                                    	<!--<label class="group"><s:property value="#request.cateName"/></label>-->
                                    	<select id="category">
                                    		<s:iterator value="charList" id="char">
                                    			<option <s:if test="#char['id'] == news.category">SELECTED</s:if> value="<s:property value="#char['id']"/>"><s:property value="#char['name']"/></option>
                                    		</s:iterator>
                                    	</select>
                                    	<select class="sorts" name="type" id="type">
                                        	<option <s:if test="type == 1">SELECTED</s:if> value="1">政策</option>
                                            <option <s:if test="type == 2">SELECTED</s:if> value="2">信息</option>
                                        </select>
                                    </td>
                                </tr>
                                <tr>
                                	<td width="87" class="col1 vt">内容：</td>
                                    <td>
                                    	<textarea class="def_ta" name="content" id="news_content"><s:property value="news.content"/></textarea>
                                        <div class="operate">
                                        	<input type="button" value="发布" class="def_btn_s1" id="publish_news"/>
                                        	<!--<a href="javascript:void(0);" class="attachment" onclick="myFile.click();">添加附件</a>-->
                                        	<div><input type="checkbox" name="isshortmsg" id="isshortmsg"/><span>短信通知</span>&nbsp;&nbsp;&nbsp;<input type="checkbox" name="isannounce" id="isannounce"/><span>公告栏</span></div>
                                        </div>
                                    </td>
                                </tr>
                                <tr>
                                	<td></td>
                                	<td>
                                    	<ul class="attach_list" id="attach_list">
                                    	
                                    	<s:iterator id="attach" value="news.attachList" status="status">
                                    		<li><a class="a1" href="<s:property value="#request.basePath"/><s:property value="path"/>" target="_blank"><s:property value="name"/></a>
                                    		<a href="javascript:void(0);" filePath="<s:property value="path"/>" class="cancl a2" onclick="cancelAttach(this)">取消</a>
                                    		</li>
                                    	</s:iterator>
                                         
                            			</ul>
                                    </td>
                                </tr>
                            </tbody></table>
                           	
                           	 <form action="mail!uploadAttach.do" id="attach_upload" method="post" enctype="multipart/form-data">
                            <div class="add_attachment_wrap">
                               	<a href="javascript:void(0);" class="attachment" style="top:0">添加附件</a><input style="top:0" type="file" onchange="uploadAttach('<s:property value="#request.basePath"/>');" name="attach" class="file_load" id="myFile" />
                               </div>
                            </form>
                            
                        	</div>
                        	
                           
                        </div>
                    </div>
                    
                </div>
            </div>
            
            <!-- right -->
           <%@include file="right.jsp" %> 
            <!--right--end-->
            <br class="clear">
        </div>
    </div>
    <%@include file="../common/footer.jsp" %>
    
    <script type="text/javascript">
    	function save(){
    		var title = $("#title").val();
    		var content = $("#news_content").val();
    		var category = $("#category").val();
    		var type = $("#type").val();
    		var isshortmsg = $("#isshortmsg").attr("checked");
    		var isannounce = $("#isannounce").attr("checked");
    		if(title == null || title == ""){
    			alert("标题不能为空！");
    			return false;
    		}
    		if(content == null || content == ""){
    			alert("内容不能为空！");
    			return false;
    		}
    		var attachList = new Array();
    		$("#attach_list li").each(function(){
    			var fileName = $(this).find("a.a1").text();
    			var filePath = $(this).find("a.a2").attr("filePath");
    			attachList.push({
    				name:fileName,
    				path:filePath
    			});
    		});
    		$("#publish_news").unbind("click");
    		$.post("news!save.do",{
    			'news.id':'<s:property value="news.id"/>',
    			'news.type':type,
    			'news.title':title,
    			'news.category':category,
    			'news.content':content,
    			'news.isShortmsg':isshortmsg?true:false,
    			'news.isAnnounce':isannounce?true:false,
    			'news.attachs':$.toJSON(attachList)
    		},function(data){
    			if(data!=null){
    				var ret = $.parseJSON(data);
    				if(ret.success == 'true'){
						window.location.href="news!view.do";
    				}
    			}
    		});
    	//	$("#send_mail_form").submit();
    	//	return false;
    	}
    	
    	$(function(){
    		$("#publish_news").click(function(){
    			save();
    		});
    	});
    </script>
</body>
</html>
